<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统管理员列表</title>
    <base th:href="${#servletContext.getContextPath()+'/'}">
    <link rel="stylesheet" type="text/css" href="static/bootstrap-3.4.1/dist/css/bootstrap.css">
    <script type="text/javascript" src="static/jquery/jquery-3.6.1.min.js"></script>
    <script type="text/javascript" src="source/interaction.js"></script>


    <script type="text/javascript">
        $(function () {
            $("#adminCheckFlag").change(function () {
                // 1.获取当前的状态值
                var val = $(this).prop("checked");
                // 2.获取需要被选中的元素
                $(".adminCheck").each(function () {
                    $(this).prop("checked", val);
                })
            });

            $("#adminBatchDelete").click(function () {
                var array = new Array();
                // 获取用户勾选的数据
                $(".adminCheck:checked").each(function () {
                    // 把数组放到数组中
                    array.push($(this).val());
                })

                sendRequest("SystemAdminServlet/batchDelete", array, function (data) {
                    if (data.code == 200) {
                        location.reload();
                    }
                });

            });
        })
    </script>
</head>
<body>
<a href="PageServlet/system/systemAdmin/adminAdd.html">添加</a>
<button class="button btn-danger" id="adminBatchDelete">批量删除</button>
<table class="table">
    <tr>
        <th>
            <input type="checkbox" id="adminCheckFlag">
        </th>
        <th>id</th>
        <th>username</th>
        <th>sex</th>
        <th>email</th>
        <th>birthday</th>
        <th>操作</th>
    </tr>

    <tr th:each="admin:${adminList}">
        <td>
            <input class="adminCheck" type="checkbox" th:value="${admin.id}">
        </td>
        <td th:text="${admin.id}"/>
        <td th:text="${admin.account}"/>
        <td th:text="${admin.sex?'男':'女'}"/>
        <td th:text="${admin.email}"/>
        <td th:text="${#dates.format(admin.birthday,'yyyy-MM-dd')}"/>
        <td>
            <a th:href="|SystemAdminServlet/selectAdminById?id=${admin.id}|">编辑</a>
            <a th:href="|SystemAdminServlet/delete?id=${admin.id}|">删除</a>
        </td>
    </tr>
</table>

</body>
</html>